const { response } = require('express');
const express = require('express');
const data = require('./data/newdata.json');
const app = express();
app.listen(80);
// 新闻列表
app.get('/list',(req,res)=>{
    let str = data.map(item=>`<p><a href="/detail?id=${item.id}">${item.newsTitle}</a></p>`).join('');
    res.send(str);
})

// 新闻详情页
app.get('/detail',(req,res)=>{
    let {id} = req.query;
    let {newsTitle,newsContent} = data.find(item=>item.id===id);
    let str = `
        <a href="/list">返回</a>
        <h3>${newsTitle}</h3>
        <p>${newsContent}</p>
    `;
    res.send(str);
})